package com.himalayan.bear.controller;

import com.alibaba.fastjson.JSONObject;
import com.himalayan.bear.common.util.StringUtils;
import com.himalayan.bear.entity.User;
import com.himalayan.bear.service.UserFileService;
import com.himalayan.bear.util.RespUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author zjk
 * @since 2019-04-25
 */
@Controller
@RequestMapping("/userFile")
public class UserFileController extends BaseController {

    @Autowired
    protected UserFileService userFileService;

    @ResponseBody
    @RequestMapping("/fileList")
    public JSONObject fileList(String parentId, HttpSession session) {
        User currentUser = getUser(session);
        if (currentUser == null) {
            return RespUtil.msg(false, "未能获取当前登陆信息 !");
        }
        if (StringUtils.isEmpty(parentId)) {
            parentId = "0";
        }
        List<Map<String, Object>> list = userFileService.listAll(parentId, currentUser.getId());
        return RespUtil.msg(true, "", list);
    }
}
